﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HappyLine
{
    public partial class EditForm : Form
    {
        public LineData res = null;
        List<LineData> ldl = null;
        public EditForm(List<LineData> ldl)
        {
            this.ldl = ldl;
            InitializeComponent();
            UpdateListBox();
           
        }
        private void UpdateListBox()
        {
            listBox1.Items.Clear();
            foreach (LineData ld in ldl) 
            {
                listBox1.Items.Add(ld.Name);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0)
            {
                MessageBox.Show("Please select item", "Hey!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            res = ldl.Find(x => x.Name == (string)listBox1.Items[listBox1.SelectedIndex]);
            Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0)
            {
                MessageBox.Show("Please select item(s) to delete", "Hey!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            foreach (string data in listBox1.SelectedItems) 
            {
                ldl.RemoveAll(x => x.Name == data);
            }
            UpdateListBox();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
